<?php
class Attachment extends Model {
	function Attachment(){
		parent::Model();
    }
    
    function insertAttachment($post_id=NULL,
    							$type=NULL,
    							$data=NULL){
    	$query = "INSERT INTO posts_attachments (post_id,
				    							type,
						    					data) VALUES ('$post_id',
										    					'$type',
										    					'$data')";
    	if($query = $this->db->query($query)){
    		return $this->db->insert_id();
    	}
    	return FALSE;
    	
    }
    
    function getAttachment($post_id=NULL){
    	$return = FALSE;
    	$query = "SELECT * FROM posts_attachments WHERE post_id='$post_id' ORDER BY id DESC";
    	$query = $this->db->query($query);
   	 	if($query->num_rows() > 0){
   	 		$return =array();
   	 		foreach ($query->result() as $row){
   	 			$return['id'][]  = $row->id;
				$return['type'][]  = $row->type;
				$return['data'][] = $row->data;
			}
    	}
    	return $return;
    }
}
    